$(function() {
	var geolocation = new BMap.Geolocation();
	geolocation.getCurrentPosition(function(r) {
		var gps_w = r.point.lat;
		var gps_j = r.point.lng;
		var token = localStorage.phone;
		$.ajax({
			url: "https://newapp.icandrive.cn/api/schoolInfo.php",
			data: {
				token: token,
				gps_w: gps_w,
				gps_j: gps_j
			},
			dataType: 'json',
			type: 'post',
			success: function(data) {
				if(data.status == 250) {
					layer.msg("请重新登录");
					setInterval(function() {
						window.location.href = "../login/log_in.html";
					}, 2000);
				}
				if(data.status == 200) {
					$(data.data).each(function() {
						$(this).each(function() {
							var distance = Math.ceil(this.distance / 1000);
							$('.content').append("<div class='schoolMessage' school_id=" + this.school_id + "><div class='mainbody_left_img'><img src=" + this.school_img + "></div><div class='mainbody_right_message'><h2 id='title'>" + this.school_name + "</h2><p>" + this.school_content + "</p><div class='clearfix'><div class='sign_up'>已报名:<span class='sign_up_number'>" + this.sign_num + "</span></div><div class='distance'><img src='locate.png' alt='距离'><span class='distance_long'>距 " + distance + "km</span></div></div></div></div>");
							$(".schoolMessage").click(function() {
								var school_id = $(this).attr('school_id');
								localStorage.school_id = school_id;
								window.location.href = "../sign/sign_up.html";
							});
						})
					});
				}
				if(data.status == 400) {
					layer.msg(data.msg);
				}
			},
			error: function() {
				layer.msg('系统繁忙', function() {
					history.go(0)
				}, 1000);
			}
		});

	}, {
		enableHighAccuracy: true
	});

});

/*点击返回按钮*/
$("#return").click(function() {
	history.back();
});

/*监听手机回退按键*/
document.addEventListener("plusready", function() {

	plus.key.addEventListener('backbutton', function() {
		window.history.back();
	}, false);

});
